const apiHostUrl = process.env.API_HOST_URL ? process.env.API_HOST_URL
  : "http://localhost:8091";
/**
 * 装配抽奖
 * @param strategyId
 */
export const strategyArmory =async (strategyId?: number ) => {
    return fetch(`${apiHostUrl}/api/v1/raffle/strategy_armory?strategyId=${strategyId}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json'
        }
    })
}
/**
 * 查询抽奖奖品列表
 * @param strategyId 抽奖策略id
 * @returns 抽奖奖品列表
 */
export const queryRaffleAwardList = async (strategyId: number) => {
  try {
      return fetch(`${apiHostUrl}/api/v1/raffle/query_raffle_award_list`, {
          method: 'POST',
          headers: {
              'Content-Type': 'application/json'
          },
          body: JSON.stringify({
              strategyId: strategyId
          })
      });
  } catch (error) {
    // 返回一个带有 json 方法的对象，保证前端解析不会报错
    return fetch("{\n" +
        "    \"code\": \"0001\",\n" +
        "    \"info\": \"调用失败\",\n" +
        "    \"data\": [\n" +
        "}");
  }
};

export const randomRaffle = async (strategyId: number) => {
  try {
      return fetch(`${apiHostUrl}/api/v1/raffle/random_raffle`, {
          method: 'POST',
          headers: {
              'Content-Type': 'application/json;charset=utf-8'
          },
          body: JSON.stringify({
              strategyId: strategyId
          })
      })
  } catch (error) {
    return {
      json: async () => ({
        code: "0001",
        info: "调用失败",
        data: {},
      }),
    };
  }
};